import 'dart:ui' as ui;
import 'package:flutter/material.dart';
import 'package:window_manager/window_manager.dart';
//导入自定义组件
import 'view/videoFormat.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  // 必须加上这一行。
  await windowManager.ensureInitialized();

  WindowOptions windowOptions = const WindowOptions(
    size: ui.Size(1266, 713),
    center: true,
    backgroundColor: Colors.transparent,
    skipTaskbar: false,
    // titleBarStyle: TitleBarStyle.hidden,
    titleBarStyle: TitleBarStyle.normal,
    minimumSize: ui.Size(851, 677), // 设置最小尺寸
  );
  windowManager.waitUntilReadyToShow(windowOptions, () async {
    await windowManager.show();
    await windowManager.focus();
  });
  runApp(const App());
}

// backgroundColor: const Color.fromARGB(255, 214, 214, 214),
class App extends StatefulWidget {
  const App({super.key});
  @override
  // ignore: library_private_types_in_public_api
  _AppState createState() => _AppState();
}

class _AppState extends State<App> {
  int _selectedIndex = 0;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        // appBar: AppBar(
        //   title: const Text('选项卡示例'),
        // ),
        body: Row(
          children: [
            // 垂直菜单
            Container(
              width: 150, // 调整宽度以适应菜单项长度
              color: const ui.Color.fromARGB(255, 71, 71, 71), // 菜单背景颜色
              child: Column(
                mainAxisAlignment: MainAxisAlignment.start,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  MenuItem(
                    icon: Icons.video_library,
                    label: '视频格式转换',
                    index: 0,
                    isSelected: _selectedIndex == 0,
                    onTap: _onMenuItemTapped,
                  ),
                  MenuItem(
                    icon: Icons.more_horiz,
                    label: '其他',
                    index: 1,
                    isSelected: _selectedIndex == 1,
                    onTap: _onMenuItemTapped,
                  ),
                ],
              ),
            ),
            // 内容区域
            Expanded(
              child: IndexedStack(
                index: _selectedIndex,
                children:const [
                  VideoFormat(),
                  OtherTabContent(),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }

  void _onMenuItemTapped(int index) {
    setState(() {
      _selectedIndex = index;
    });
  }
}

class MenuItem extends StatelessWidget {
  final IconData icon;
  final String label;
  final int index;
  final bool isSelected;
  final Function(int) onTap;

  const MenuItem({
    super.key,
    required this.icon,
    required this.label,
    required this.index,
    required this.isSelected,
    required this.onTap,
  });

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () => onTap(index),
      child: Container(
        color: isSelected
            ? const ui.Color.fromARGB(255, 103, 80, 164)
            : Colors.transparent,
        padding: const EdgeInsets.symmetric(vertical: 16.0),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            const SizedBox(width: 16.0), // 左侧填充
            Icon(icon, color: Colors.white),
            const SizedBox(width: 8),
            Text(
              label,
              style: TextStyle(
                color: Colors.white,
                fontWeight: isSelected ? FontWeight.bold : FontWeight.normal,
              ),
            ),
            const SizedBox(width: 16.0),
          ],
        ),
      ),
    );
  }
}

class OtherTabContent extends StatelessWidget {
  const OtherTabContent({super.key});

  @override
  Widget build(BuildContext context) {
    return const Center(
      child: Text('其他选项卡内容'),
    );
  }
}
